package net.src.socket2;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Scanner;

public class ClientDemo2 {
    public static void main(String[] args) throws Exception {
        System.out.println("启动客户端成功!");
        //连接与服务器的socket
        Socket socket = new Socket(InetAddress.getLocalHost(),7777);

        //从socket通信管道中获取字节输出流,发送数据
        OutputStream os = socket.getOutputStream();
        //把它包装成高级的打印流
        PrintStream ps = new PrintStream(os);

        Scanner sc = new Scanner(System.in);
        while(true){
            //发送消息
            System.out.print("请说:");
            ps.println(sc.nextLine());
            ps.flush();//发完要刷新,不然在缓冲区
        }


        //tcp通信不要轻易的关闭管道,等关机或者用户主动关闭
    }
}
